<template>
  <div class="login">
    <el-form ref="form" class="form" :model="form" :rules="rules">
      <div class="logo">
        <img src="@/assets/common/login-logo.png" alt="">
      </div>
      <el-form-item prop="mobile">
        <el-input v-model="form.mobile" prefix-icon="el-icon-user-solid" />
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="form.password"
          type="password"
          prefix-icon="el-icon-lock"
          show-password
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="btn" @click="submit">登录</el-button>
      </el-form-item>
      <el-form-item>
        <span class="text">还没有账号?立即注册</span>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      form: {
        mobile: '13800000002',
        password: '123456'
      },
      rules: {
        mobile: [
          { required: true, message: '必填', trigger: 'change' },
          {
            validator: (rules, value, callback) => {
              const reg =
                /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('手机号格式不正确'))
              }
            },
            trigger: 'change'
          }
        ],
        password: [{ required: true, message: '必填', trigger: 'change' }]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate(async(result) => {
        //  登录
        await this.$store.dispatch('user/toLogin', this.form)
        this.$message.success('登录成功')
        const redirect = this.$route.query.redirect || '/'
        this.$router.push(redirect)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background: url(~@/assets/common/logBg.png);
  display: flex;
  justify-content: center;
  align-items: center;
  .form {
    width: 520px;
    height: 400px;
    .logo {
      text-align: center;
      padding-bottom: 25px;
    }
    .btn {
      width: 100%;
      background-color: #407ffe;
    }
    .text {
      text-align: center;
      color: #fff;
    }
  }
  ::v-deep .el-form-item__content {
    text-align: center;
  }
  // .el-form-item {
  //   border: 1px solid rgba(255, 255, 255, 0.1);
  //   background: rgba(255, 255, 255, 0.7); // 输入登录表单的背景色
  //   border-radius: 5px;
  //   color: #454545;
  // }
}
</style>
